package org.example.aidemo.service.impl;

import org.example.aidemo.mapper.UserMemoMapper;
import org.example.aidemo.pojo.UserMemo;
import org.example.aidemo.service.UserMemoService;
import org.example.aidemo.service.UserService;
import org.example.aidemo.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserMemoServiceImpl implements UserMemoService {
    @Autowired
    private UserMemoMapper userMemoMapper;
    @Autowired
    private SecurityUtils securityUtils;
    @Autowired
    private UserService userService;
    @Override
    public List<UserMemo> getUserMemoByUserId(Long UserId) {
        return userMemoMapper.getUserMemoByUserId(UserId);
    }
    @Override
    public void deleteUserMemo(List<Long> ids){
        for(Long id : ids){
            userMemoMapper.deleteUserMemo(id);
        }
    }
    @Override
    public UserMemo addUserMemo(String memo){
        System.out.println(securityUtils.getCurrentUsername()+">>>>>");
        Long userid=userService.findByUsername(securityUtils.getCurrentUsername()).getId();
        UserMemo userMemo=new UserMemo();
        userMemo.setUserId(userid);
        userMemo.setMemo(memo);
        userMemo.setCreateTime(LocalDateTime.now());
        userMemo.setUpdateTime(LocalDateTime.now());
        userMemoMapper.addUserMemo(userMemo);
        return userMemo;
    }

}
